﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using Top.Web;
using Top.Web.Api;
using Top.Web.Api.Filters;
using Top.Core;
using Top.PointStore.Business;
using Top.PointStore.Business.Models;
using Top.PointStore.Web.Filters;

namespace Top.PointStore.Web.Controllers
{
    [Provider]
    public class PointStoreAuthController : ApiBase
    {
        [Login]
        public object Auth_AddUser(T_PointStoreAdminAuthority model)
        {            
            return PointStoreAuthManager.Auth_AddUser(model);
        }

        [Login]
        public object Auth_EditUser(T_PointStoreAdminAuthority model)
        {
            return PointStoreAuthManager.Auth_EditUser(model);
        }

        [Login]
        public async Task<IList<T_PointStoreAdminAuthority>> Auth_GetList(int pageIndex = 1, int pageSize = 10)
        {
            var pager = Pager.Create(pageIndex, pageSize);
            int cityKid = Get("cityKid", -1);
            int isOpen = Get("isOpen", -1);
            string loginName = Get("loginName", "");
            try
            {
                return await PointStoreAuthManager.Auth_GetList(pager, cityKid, isOpen, loginName,pUser.PointStoreAuth);
            }
            catch (Exception)
            {                
                throw;
            }            
        }

        [Login]
        public object Auth_GetAuthCityList()
        {
            return PointStoreAuthManager.Auth_GetAuthCityList(pUser.PointStoreAuth);
        }

        [Login]
        public object Auth_GetAuthByLoginName()
        {
            string loginName = Get("loginName", "");
            return PointStoreAuthManager.Auth_GetAuthByLoginName(loginName);
        }
    }
}